/* File 3 of 3 to create CCK results. */



#delimit ;
clear all;
local outfile "GWgapr10_CCKIV";
set more off;


di _n "$S_DATE $S_TIME";


* our optimal T;
local T 9.95; * get this from GWgapr10_CCKnorm.do;





********************************************************************************;
* IV; 


use temp_befcol, clear;

gen excVA = max(0,lnval_ad_pw - `T') if lnval_ad_pw!=.;
label var excVA "lnval_ad_pw in excess of `T'";

*** normalising FEs;

foreach g in m f {;

	qui sum ffe_`g' if lnval_ad_pw< `T' [fweight = L_hc_rdd];
	gen ffe_`g'nva = ffe_`g' - r(mean);
};


qui reg ffe_fnva excVA [aweight = L_hc_t], cluster(pent);

* next line, when uncommented, confidentialises observation count in output;
*rndobs N;
reg;

ivregress 2sls ffe_fnva (ffe_mnva = excVA) [aweight = L_hc_t], first cluster(pent);
* next line, when uncommented, confidentialises observation count in output;
*rndobs N;
ivregress;

